import 'package:flutter/material.dart';
import 'package:intl/intl.dart';import '../../generated/intl/messages_all.dart';
import '../language/LocalizationsResource.dart';



class DemoLocalizations {

  static DemoLocalizations? of (BuildContext context)  {
    return Localizations.of<DemoLocalizations>(context, DemoLocalizations);
  }

  String get title {
    return Intl.message(
      'Flutter APP',
      name: 'title',
      desc: 'Title for the Demo application',
    );
  }

  static Future<LocalizationsResource> load(Locale locale) {
    final String name = locale.countryCode!.isEmpty ? locale.languageCode : locale.toString();
    final String localeName = Intl.canonicalizedLocale(name);

    return initializeMessages(localeName).then((b) {
      Intl.defaultLocale = localeName;
      return LocalizationsResource(true);
    });
  }
}

class ProxyLocalizations extends LocalizationsDelegate<LocalizationsResource> {

  ProxyLocalizations();

  @override
  bool isSupported(Locale locale) {
    return ['en', 'zh'].contains(locale.languageCode);
  }

  @override
  Future<LocalizationsResource> load(Locale locale) {
    print('$locale');
    return  DemoLocalizations.load(locale);
  }

  @override
  bool shouldReload(LocalizationsDelegate<LocalizationsResource> old) => false;

}